﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Grpc.Net.Client;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace ShopGrpcClient.Controllers
{
    public class CategoriesController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public CategoriesController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }
        public IActionResult Index()
        {
            //1.创建连接通道Grpc通道
            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            //2.创建Grpc客户端
            ShopGrpcService.Categories.CategoriesClient client = new ShopGrpcService.Categories.CategoriesClient(channel);
            //3.调用方法并获取返回对象
            var resp = client.GetCategoriesList(new Google.Protobuf.WellKnownTypes.Empty());
            return View(resp.CategoryInfos.ToList());
            
        }
    }
}